package com.sgb.kjwl.viewmodel.enterprise;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.EnterpriseAPIManager;
import com.sgb.kjwl.model.entity.enterprise.UserServiceTeamDetailEntity;
import com.sgb.kjwl.view.ui.activity.enterprise.UserCenterTeamDetailActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class UserCenterTeamDetailModel extends BaseViewModel {

    private UserCenterTeamDetailActivity userCenterTeamDetailActivity;

    public UserCenterTeamDetailModel(UserCenterTeamDetailActivity userCenterTeamDetailActivity) {
        this.userCenterTeamDetailActivity = userCenterTeamDetailActivity;
    }


    /**
     * 个人中心团队信息
     */
    public void getTeamQueryDetailUserCenter() {
        DialogHelper.showProgressDialog(userCenterTeamDetailActivity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        EnterpriseAPIManager.getInstance().getEnterpriseAPI().getTeamDetailUserCenter().enqueue(new Callback<BaseEntity<UserServiceTeamDetailEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<UserServiceTeamDetailEntity>> call, Response<BaseEntity<UserServiceTeamDetailEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getData() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    userCenterTeamDetailActivity.setShowDetails(response.body().getData());
                } else {
                    MToast.showToast(userCenterTeamDetailActivity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<UserServiceTeamDetailEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }
}
